"""
ResumeMyWay
An app which allows you to create an online personal professional journal and 
easily generate different versions of your resume for different purposes.

Copyright (c) 2011 Jay Baxter, Saher Ahwal, Wesam Manassra, Arun Saigal
"""

#from flaskext.sqlalchemy import SQLAlchemy
from .. import db
from .. import utils

class Item(db.Model):
    # this declaration results in an autoincrementing id
    id = db.Column(db.Integer, primary_key=True)
    
    # declare many-one relationship to user
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User', backref=db.backref('items', lazy='dynamic'))
    
    # declare many-one relationship to self
    parent_id = db.Column(db.Integer, db.ForeignKey('item.id'))
    parent = db.relationship('Item', backref=db.backref('subitems', remote_side=[id], lazy='dynamic'))
    
    content = db.Column(db.Text)

    def __init__(self, dict):
        self.content = dict['content']

    def __repr__(self):
        return '<Item %s owned by %r with parent %r>' % (self.content, self.user, self.parent)